import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入全局样式
import './assets/global.scss'
// 引入图文字体
import './assets/font/iconfont.css'
// 引入element
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import axios from 'axios'
// 引入复制
// import VueClipboard from 'vue3-clipboard'
// VueClipboard.config.autoSetContainer = true
// 配置请求的根路径
axios.defaults.baseURL = 'http://39.101.171.163:20001/api/front/'
axios.interceptors.request.use((config) => {
  config.headers['Content-Type'] = 'application/json'
  if (window.sessionStorage.getItem('token')) {
    config.headers['Authori-zation'] = window.sessionStorage.getItem('token')
  }

  return config
})


const app = createApp(App)
app.config.globalProperties.$http = axios

// 浏览器 setSessionItem 存储监听
app.config.globalProperties.setSessionItem = function (key, newVal) {
  // 创建 StorageEvent 事件
  let newStorageEvent = document.createEvent('StorageEvent')
  const storage = {
    setItem: function (k, val) {
      sessionStorage.setItem(k, val)

      // 初始化 StorageEvent 事件
      newStorageEvent.initStorageEvent(
        'setItem', // 事件别名
        false,
        false,
        k,
        null,
        val,
        null,
        null
      )

      // 派发事件
      window.dispatchEvent(newStorageEvent)
    },
  }
  return storage.setItem(key, newVal)
}
app.config.productionTip = false
app.use(store)
// VueClipboard.config.autoSetContainer = true
// app.use(VueClipboard)
app.use(router)
app.use(ElementPlus)
// app.use(axios)
app.mount('#app')
